package com.ruoyi.voucher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.SubjectType;
import com.ruoyi.voucher.service.ISubjectTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 科目分类Controller
 * 
 * @author sfk
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/SubjectType")
public class SubjectTypeController extends BaseController
{
    @Autowired
    private ISubjectTypeService subjectTypeService;

    /**
     * 查询科目分类列表
     */
    @RequiresPermissions("voucher:SubjectType:list")
    @GetMapping("/list")
    public TableDataInfo list(SubjectType subjectType)
    {
        startPage();
        List<SubjectType> list = subjectTypeService.selectSubjectTypeList(subjectType);
        return getDataTable(list);
    }

//    @RequiresPermissions("voucher:SubjectType:list")
    @GetMapping("/searchSubjectTypeList")
    public AjaxResult searchSubjectTypeList(SubjectType subjectType)
    {
//        startPage();
        List<SubjectType> list = subjectTypeService.selectSubjectTypeList(subjectType);
        return success(list);
    }

    /**
     * 导出科目分类列表
     */
    @RequiresPermissions("voucher:SubjectType:export")
    @Log(title = "科目分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubjectType subjectType)
    {
        List<SubjectType> list = subjectTypeService.selectSubjectTypeList(subjectType);
        ExcelUtil<SubjectType> util = new ExcelUtil<SubjectType>(SubjectType.class);
        util.exportExcel(response, list, "科目分类数据");
    }

    /**
     * 获取科目分类详细信息
     */
    @RequiresPermissions("voucher:SubjectType:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(subjectTypeService.selectSubjectTypeByTypeId(typeId));
    }

    /**
     * 新增科目分类
     */
    @RequiresPermissions("voucher:SubjectType:add")
    @Log(title = "科目分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid SubjectType subjectType)
    {
        return toAjax(subjectTypeService.insertSubjectType(subjectType));
    }

    /**
     * 修改科目分类
     */
    @RequiresPermissions("voucher:SubjectType:edit")
    @Log(title = "科目分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectType subjectType)
    {
        return toAjax(subjectTypeService.updateSubjectType(subjectType));
    }

    /**
     * 删除科目分类
     */
    @RequiresPermissions("voucher:SubjectType:remove")
    @Log(title = "科目分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(subjectTypeService.deleteSubjectTypeByTypeIds(typeIds));
    }
}
